package team.first.moiveapiv1.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import team.first.moiveapiv1.domain.Movie;
import team.first.moiveapiv1.dto.RequestMovie;
import team.first.moiveapiv1.mapper.MovieMapper;
import team.first.moiveapiv1.service.MovieService;

import java.util.List;

/**
 * @Author: HAPPY
 * @Project_name: project
 * @Package_name: team.first.moiveapiv1.service.impl
 * @Date: 2021/11/25 11:00
 * @Description：
 */
@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, Movie> implements MovieService {

    @Autowired
    MovieMapper movieMapper;

    @Override
    public List<Movie> getMovieList(RequestMovie requestMovie) {
        // 参数合法性校验
        if (requestMovie.getPageNumber() == null) {
            // 默认第一页
            requestMovie.setPageNumber(1);
        }
        if (requestMovie.getPagerSize() == null) {
            // 默认查询十条记录
            requestMovie.setPagerSize(10);
        }
        // 初始化起点
        requestMovie.setOffset((requestMovie.getPageNumber() - 1) * requestMovie.getPagerSize());

        if (!"DESC".equalsIgnoreCase(requestMovie.getOrderDirection())) {
            // 默认升序
            requestMovie.setOrderDirection("ASC");
        }


        return movieMapper.selectMovieByPost(requestMovie);
    }
}

